package com.zj.study.utils.validation.validator.positive;



import com.zj.study.utils.validation.annotation.constraint.Positive;
import com.zj.study.utils.validation.validator.ConstraintValidator;
import org.springframework.lang.NonNull;

/**
 * @author 谭耀飞
 * @since 2020.12.0
 */
public abstract class AbstractPositiveValidator<T> implements
    ConstraintValidator<Positive, T> {

  @Override
  final
  public boolean isValid(@NonNull Positive positive, T value) {
    return value == null || compare(value);
  }

  /**
   * 比较方法实现
   *
   * @param value 校验值
   * @return 是否合法
   */
  abstract boolean compare(@NonNull T value);
}
